﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Willows.Model
{
	public partial class SignalWriterInterface
		: ChannelWriterInterface, ISignal
	{
		public string WriteZeroSignalFlowGraphName
		{
			get { return string.Format("signal_{0}_write_zero", LocalName); }
		}

		public virtual void Refine(RefinedModel.Model model)
		{
			Module module = Parent as Module;
			Weazel.Willows.RefinedModel.Datapath datapath = module.Datapath;

			Weazel.Willows.RefinedModel.SignalFlowGraph sfg =
				new Weazel.Willows.RefinedModel.SignalFlowGraph(datapath, null, WriteZeroSignalFlowGraphName);

			sfg.Expressions.Add(
				new Weazel.Gezel.Model.BinaryExpression(
					Weazel.Gezel.Model.ExpressionType.Assignment,
						new Weazel.Gezel.Model.LeafExpression(Weazel.Gezel.Model.ExpressionType.Identifier, LocalName),
						new Weazel.Gezel.Model.LeafExpression(Weazel.Gezel.Model.ExpressionType.Constant, "0")
					)
				);

			datapath.SignalFlowGraphs.Add(this.WriteZeroSignalFlowGraphName, sfg);
		}
	}
}
